package com.gxa.luckin.cart.controller;

import com.gxa.luckin.cart.service.CartService;
import com.gxa.luckin.core.exception.BusinessException;
import com.gxa.luckin.core.pojo.CartItem;
import com.gxa.luckin.core.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.net.URISyntaxException;
import java.util.Map;

/**
 * @author: XHZ
 * @date: 16:55 2021/7/16
 */
@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    CartService cartService;

    @PostMapping("/queryUserCartItem")
    public Result queryUserCartItem(Long userId, String skuId) throws BusinessException {
        CartItem cartItem = cartService.queryUserCartItem(userId, skuId);
        return new Result(cartItem);
    }

    @GetMapping("/queryUserCart")
    public Result queryUserCart(Long userId){
        Map map = cartService.queryUserCart(userId);
        return new Result(map);
    }

    @GetMapping("/addGoodsToCart")
    public Result addGoodsToCart(Long userId, String skuId, Integer num) throws BusinessException, URISyntaxException {
        cartService.addGoodsToCart(userId,skuId,num);
        return new Result("成功");
    }
}
